<?php
require_once('config.php');

$barcode_config = array(
	'font_name' => 'ariblk.ttf',
	'font_size' => 8,
	'barcode_type' => 'code128',
	'resolution' => 1,
	'output' => 1,
	'thickness' => 30,
	'show_label' => true
);

if(isset($_GET['text'])) {
	require(DIR_SYSTEM.'/vendor/barcode/BCGColor.php');
	require(DIR_SYSTEM.'/vendor/barcode/BCGBarcode.php');
	require(DIR_SYSTEM.'/vendor/barcode/BCGDrawing.php');
	require(DIR_SYSTEM.'/vendor/barcode/BCGFont.php');
	include(DIR_SYSTEM. '/vendor/barcode/BCG' . $barcode_config['barcode_type'] . '.barcode.php');
	$font = new BCGFont(DIR_SYSTEM.'/vendor/barcode/font/'.$barcode_config['font_name'], $barcode_config['font_size']);
	$color_black = new BCGColor(0, 0, 0);
	$color_white = new BCGColor(255, 255, 255);
	$codebar = 'BCG'.$barcode_config['barcode_type'];
	$code_generated = new $codebar();
	$code_generated->setThickness($barcode_config['thickness']);
	$code_generated->setScale($barcode_config['resolution']);
	$code_generated->setBackgroundColor($color_white);
	$code_generated->setForegroundColor($color_black);
	$code_generated->setFont($font);
	if (isset($_GET['text_ext'])) {
		$code_generated->parse($_GET['text'], $_GET['text_ext']);
	} else {
		$code_generated->parse($_GET['text']);
	}
	if (!$barcode_config['show_label']) {
		$code_generated->setLabel('');
	}
	$drawing = new BCGDrawing('', $color_white);
	$drawing->setBarcode($code_generated);
	$drawing->draw();
	if(intval($barcode_config['output']) === 1) {
		header('Content-Type: image/png');
	} elseif(intval($barcode_config['output']) === 2) {
		header('Content-Type: image/jpeg');
	} elseif(intval($barcode_config['output']) === 3) {
		header('Content-Type: image/gif');
	}

	$drawing->finish(intval($barcode_config['output']));
}
else{
	header('Content-Type: image/png');
	readfile(DIR_SYSTEM.'/vendor/barcode/error.png');
}
?>